<template>
  <div class="analysis-card">
    <h3 class="analysis-title level-title">星级</h3>
    <div class="metric-item">
      <span class="item-label">评分星级</span>
      <div class="item-value">
        <div class="star-rating">
          <div class="stars-container">
            <div class="stars-background">
              <span v-for="i in 5" :key="i" class="star">★</span>
            </div>
            <div class="stars-foreground" :style="{ width: `${(Number(getData('评价统计-星级')) / 5) * 100}%` }">
              <span v-for="i in 5" :key="i" class="star">★</span>
            </div>
          </div>
        </div>
        <span class="amount">{{ getData('评价统计-星级') }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ReportSection } from '@/types/report'

interface Props {
  sectionData: ReportSection
}

const props = defineProps<Props>()

const getData = (key: string): string => {
  const item = props.sectionData.items.find(item => item.name === key)
  return item?.value || '-'
}
</script>

<style scoped>
.analysis-card {
  margin-bottom: 20px;
  padding: 20px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.level-title {
  font-size: 18px;
  color: #2d3748;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e2e8f0;
}

.metric-item {
  display: flex;
  align-items: center;
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
}

.item-label {
  font-size: 14px;
  color: #4a5568;
  min-width: 80px;
  margin-right: 16px;
  flex-shrink: 0;
}

.item-value {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  width: 100%;
}

.star-rating {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-start;
}

.stars-container {
  position: relative;
  display: inline-block;
  font-size: 24px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

.stars-background {
  color: #e2e8f0;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.stars-foreground {
  position: absolute;
  top: 0;
  left: 0;
  white-space: nowrap;
  overflow: hidden;
  color: #f6ad55;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.star {
  display: inline-block;
  margin-right: 4px;
  transform: scale(1.1);
  transition: transform 0.2s ease;
}

.star:last-child {
  margin-right: 0;
}

.amount {
  font-size: 24px;
  font-weight: 600;
  color: #2d3748;
  margin-left: 8px;
}
</style>